package com.tutu.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Program: SpringBoot
 * @Description: fanout交换机队列的配置
 * @Author: JK.TuTu
 * @Create: 2022-11-09 11:48
 **/
@Configuration
public class ExchangeConfig {
    //声明fanout交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("tutu.fanout");
    }

    //声明第一个队列
    @Bean
    public Queue queue1(){
        return new Queue("fanout.queue1");
    }

    //绑定第一个队列和交换机
    @Bean
    public Binding bindingQueue1(Queue queue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    //声明第二个队列
    @Bean
    public Queue queue2(){
        return new Queue("fanout.queue2");
    }

    //绑定第二个队列和交换机
    @Bean
    public Binding bindingQueue2(Queue queue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue2).to(fanoutExchange);
    }
}
